<template>
  <div class="app-container">
    <div class="handle-content">
      <el-input v-if="this.$store.getters.role.store_id == 0" v-model="storeId" placeholder="请输入店铺id" style="width: 200px;margin-right: 10px;">
        <el-button slot="append" @click="search">查询</el-button>
      </el-input>
      <el-button slot="append" @click="dialogSure">发放</el-button>
      <span class="right">
        <el-button type="primary" @click="exportExcel">
          导出
        </el-button>
      </span>
    </div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>汇总信息</span>
      </div>
      <div class="text item">
        {{ '上个月报单奖励：' + monthSum }}
      </div>
      <br>
      <br>
      <div class="text item">
        {{ '上个月招商奖励：' + recommendSum }}
      </div>
    </el-card>
    <el-table v-loading="listLoading" :data="list" element-loading-text="拼命加载中" border fit highlight-current-row>
      <el-table-column v-if="this.$store.getters.role.store_id == 0" label="店铺ID" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.store_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报单中心ID" align="center">
        <template slot-scope="scope">
          {{ scope.row.user_id }}
        </template>
      </el-table-column>
      <el-table-column label="应得报单奖励" align="center">
        <template slot-scope="scope">
          <span style="color: rgb(64, 158, 255);cursor:pointer;">{{ scope.row.month }}</span>
        </template>
      </el-table-column>
      <el-table-column label="应得招商奖励" align="center">
        <template slot-scope="scope">
          <span style="color: rgb(64, 158, 255);cursor:pointer;">{{ scope.row.recommend }}</span>
        </template>
      </el-table-column>
    </el-table>
    <dialog-model ref="dialog" @sure="send" />
  </div>
</template>

<script>
/* eslint-disable */
import { temaMonthList,temaMonthSend } from '@/api/member'
import { Message } from 'element-ui'
import DialogModel from '@/components/Dialog'
import { getToken } from '@/utils/auth' // get token from cookie
export default {
  components: { DialogModel },
  data() {
    return {
      list: [],
      listLoading: false,
      listQuery: {
        storeId: 0,
      },
      storeId: '',
      monthSum: 0,
      recommendSum: 0,
      path:'',
    }
  },

  mounted() {
    this.getList()
  },

  methods: {
    getList() {
      this.listLoading = true
      temaMonthList(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.data
        this.monthSum = response.data.monthSum
        this.recommendSum = response.data.recommendSum
        this.path = response.data.path
        this.listLoading = false
      })
    },
    dialogSure(){
      this.$refs.dialog.showDialog('您确定要发放报单奖励吗?')
    },
    send() {
      this.listLoading = true
      this.listQuery.storeId = this.storeId
      temaMonthSend(this.listQuery).then(response => {
        console.log(response)
        Message({
          message: response.info,
          type: 'success',
          duration: 2000
        })
        // this.getList()
        // this.listLoading = false
      })
    },
    search() {
      this.listQuery.storeId = this.storeId
      console.log(this.storeId)
      console.log(this.listQuery)
      this.getList()
    },
    exportExcel() {
      const url = this.path + '?storeId=' + this.listQuery.storeId + '&token=' + getToken() + '&report=' + true

      location.href = url
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.app-container{
    .handle-content{
        margin-bottom: 20px;
        .right{
            float: right;
        }
    }
}
</style>
<style>
.el-table .warning-row {
}

.el-table .success-row {
}
</style>
